package com.itcast.demo_one.kotlin

fun main(args: Array<String>) {

    val car = Car("小轿车")
    car.show()

    val car2 = Car("自行车")
    car2.show()

    val car3 = Car("自定义车辆-A", 100)
    car3.show()

}

class Car(var name: String){
    var wheels = 0
    // 初始代码块
    init {
        wheels = when(name){
            "自行车" -> 2
            "小轿车" -> 4
            "大货车" -> 12
            else -> 4
        }
    }

    // 次构造函数
    constructor(name: String, wheels: Int): this(name){
        this.wheels = wheels
    }

    fun show(){
        println("车辆名称: $name, 车轮数量: $wheels")
    }
}